package com.example.leetdemo.finash;

import java.util.ArrayList;
import java.util.List;

public class Solution2420 {

    public List<Integer> goodIndices(int[] nums, int k) {
        int[] dp1 = new int[nums.length];
        dp1[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i - 1] <= 0) {
                dp1[i] = dp1[i - 1] + 1;
            } else {
                dp1[i] = 1;
            }
        }
        int[] dp2 = new int[nums.length];
        dp2[nums.length - 1] = 1;
        for (int i = nums.length - 2; i >=0; i--) {
            if (nums[i + 1] - nums[i] >= 0) {
                dp2[i] = dp2[i + 1] + 1;
            } else {
                dp2[i] = 1;
            }
        }
        List<Integer> list = new ArrayList<>();
        for (int i = 1; i < nums.length - 1; i++) {
            if (dp1[i - 1] >= k && dp2[i + 1] >= k) {
                list.add(i);
            }
        }
        return list;
    }

    public static void main(String[] args) {
        Solution2420 solution2420 = new Solution2420();
        solution2420.goodIndices(new int[] {878724,201541,179099,98437,35765,327555,475851,598885,849470,943442}
        , 4);
    }
}
